Tags: #◇Computer Science #◇CSOPESY #◇Operating Systems #◇Reviewer #◇Finals #◇Quiz
CSOPESY Midterm Mock Exam
◇Cover Sheet
Course: CSOPESY — Operating Systems
Coverage: Weeks 1-8 (Modules 1-3)
Format: Part I — Multiple Choice (25 pts) | Part II — Problem Solving (35 pts) | Total: 60 pts
Instructions: This is a timed mock. Set a timer for 75 minutes before starting. Do not refer to your notes until after completing all sections.
◇Part I: Problem Solving (35 points)
Problem 1: CPU Scheduling (25 pts)
Given the following set of processes:
| Process | Arrival Time (AT) | Burst Time (BT) | Priority (1 = Highest) |
|---|---|---|---|
| P1 | 0 | 6 | 2 |
| P2 | 2 | 4 | 1 |
| P3 | 4 | 8 | 4 |
| P4 | 5 | 3 | 3 |
| P5 | 6 | 5 | 5 |
For each of the following four algorithms, draw the Gantt chart and compute the CT, TAT, WT per process and the Average Waiting Time:
(a) First-Come First-Served (FCFS) — 6 pts
(b) Non-Preemptive Priority Scheduling (lower number = higher priority) — 6 pts
(c) Shortest Remaining Time First (SRTF) — 7 pts
(d) Round Robin with time quantum — 6 pts
Formulas:
Problem 2: Effective Access Time (5 pts)
A system uses a two-level cache-to-memory hierarchy with the following parameters:
- Cache hit rate:
- Cache access time: ns
- Main memory access time: ns
- Access model: Sequential (memory is accessed only on a cache miss, after the cache lookup completes)
(a) Using the EAT formula, compute the Effective Access Time. Show your work. (3 pts)
(b) If the cache hit rate improves to , compute the new EAT. (2 pts)
Problem 3: Amdahl's Law (5 pts)
A parallel image-processing application is profiled. Analysis reveals that 30% of its execution is inherently sequential (cannot be parallelized — reading input, writing output, and maintaining state). The remaining 70% can be distributed across any number of cores.
(a) Using Amdahl's Law, compute the maximum theoretical speedup with processor cores. Show your work. (3 pts)
(b) As the number of cores approaches infinity (), what is the absolute maximum speedup this application can theoretically achieve? What does this imply about the value of simply adding more cores? (2 pts)
◇Problem Solving Answer Key
Problem 1 Solutions
Process Table:
| Process | AT | BT | Priority |
|---|---|---|---|
| P1 | 0 | 6 | 2 |
| P2 | 2 | 4 | 1 |
| P3 | 4 | 8 | 4 |
| P4 | 5 | 3 | 3 |
| P5 | 6 | 5 | 5 |
(a) FCFS
Gantt Chart:
| P | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 6 | 6 | 0 |
| P2 | 2 | 4 | 10 | 8 | 4 |
| P3 | 4 | 8 | 18 | 14 | 6 |
| P4 | 5 | 3 | 21 | 16 | 13 |
| P5 | 6 | 5 | 26 | 20 | 15 |
Avg WT: ms
(b) Non-Preemptive Priority (1 = Highest)
Selection logic:
- t=0: Only P1 (pri=2) → run P1 (0→6, CT=6)
- t=6: Available: P2(1), P3(4), P4(3), P5(5) — all arrived by t=6. Highest: P2(1) → 6→10
- t=10: Available: P3(4), P4(3), P5(5). Highest: P4(3) → 10→13
- t=13: Available: P3(4), P5(5). Highest: P3(4) → 13→21
- t=21: Only P5(5) → 21→26
Gantt Chart:
| P | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 6 | 6 | 0 |
| P2 | 2 | 4 | 10 | 8 | 4 |
| P3 | 4 | 8 | 21 | 17 | 9 |
| P4 | 5 | 3 | 13 | 8 | 5 |
| P5 | 6 | 5 | 26 | 20 | 15 |
Avg WT: ms
(c) SRTF (Preemptive SJF)
Event-by-event trace:
| Time | Event | CPU (rem) | Action |
|---|---|---|---|
| t=0 | P1 arrives (6) | P1(6) | Start P1 |
| t=2 | P2 arrives (4). P2(4) = P1 rem(4) → tie, no preempt | P1(4), P2(4) | Continue P1 |
| t=4 | P3 arrives (8). P3(8) > P1 rem(2) → continue | P1(2), P2(4), P3(8) | Continue P1 |
| t=5 | P4 arrives (3). P4(3) > P1 rem(1) → continue | P1(1), P2(4), P3(8), P4(3) | Continue P1 |
| t=6 | P1 done. P5 arrives (5). Queue: P2(4), P3(8), P4(3), P5(5). Shortest: P4(3) | — | Start P4 |
| t=9 | P4 done. Queue: P2(4), P3(8), P5(5). Shortest: P2(4) | — | Start P2 |
| t=13 | P2 done. Queue: P3(8), P5(5). Shortest: P5(5) | — | Start P5 |
| t=18 | P5 done. Only P3(8) | — | Start P3 |
| t=26 | P3 done | — | — |
Gantt Chart:
| P | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 6 | 6 | 0 |
| P2 | 2 | 4 | 13 | 11 | 7 |
| P3 | 4 | 8 | 26 | 22 | 14 |
| P4 | 5 | 3 | 9 | 4 | 1 |
| P5 | 6 | 5 | 18 | 12 | 7 |
Avg WT: ms
(d) Round Robin (q = 2)
Queue trace (convention: new arrivals at quantum boundary join before re-queued process):
| Time | Run | Rem After | Queue After |
|---|---|---|---|
| 0→2 | P1 | P1(4) | [P2, P1] — P2 at t=2 |
| 2→4 | P2 | P2(2) | [P1, P3, P2] — P3 at t=4 |
| 4→6 | P1 | P1(2) | [P3, P2, P4, P5, P1] — P4 at t=5, P5 at t=6 |
| 6→8 | P3 | P3(6) | [P2, P4, P5, P1, P3] |
| 8→10 | P2 | DONE (CT=10) | [P4, P5, P1, P3] |
| 10→12 | P4 | P4(1) | [P5, P1, P3, P4] |
| 12→14 | P5 | P5(3) | [P1, P3, P4, P5] |
| 14→16 | P1 | DONE (CT=16) | [P3, P4, P5] |
| 16→18 | P3 | P3(4) | [P4, P5, P3] |
| 18→19 | P4 | DONE (CT=19) | [P5, P3] |
| 19→21 | P5 | P5(1) | [P3, P5] |
| 21→23 | P3 | P3(2) | [P5, P3] |
| 23→24 | P5 | DONE (CT=24) | [P3] |
| 24→26 | P3 | DONE (CT=26) | — |
Gantt Chart:
| P | AT | BT | CT | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 6 | 16 | 16 | 10 |
| P2 | 2 | 4 | 10 | 8 | 4 |
| P3 | 4 | 8 | 26 | 22 | 14 |
| P4 | 5 | 3 | 19 | 14 | 11 |
| P5 | 6 | 5 | 24 | 18 | 13 |
Avg WT: ms
[!note] Algorithm Comparison Summary
Algorithm Avg WT SRTF 5.8 ms (best) Non-Preemptive Priority 6.6 ms FCFS 7.6 ms Round Robin (q=2) 10.4 ms SRTF minimizes average waiting time. RR with a small quantum performs worst here due to high context switch turnover across 5 processes.
Problem 2 Solution: EAT
(a) H = 0.92:
(b) H = 0.99:
Insight: Improving cache hit rate from 92% to 99% cuts EAT by 67% (21.0 → 7.0 ns), underscoring why CPU designers invest heavily in cache design.
Problem 3 Solution: Amdahl's Law
(a) N = 4 cores, S = 0.30:
(b) N → ∞:
Implication: No matter how many cores are added, the maximum speedup is capped at 3.33x because 30% of the application is sequential and cannot be parallelized. Adding cores beyond a certain point yields negligible returns — the sequential bottleneck becomes the only limiting factor. This is why optimizing the sequential portion (reducing ) is often more impactful than simply adding more hardware.
◇References & Navigation
- Related Notes: ◇CSOPESY 01 - Introduction, ◇CSOPESY 02 - Operating System Structure, ◇CSOPESY 03 - IO and Display, ◇CSOPESY 04 - Processes, ◇CSOPESY 05 - Threads, ◇CSOPESY 06 - CPU Scheduling, ◇CSOPESY 07 - Synchronization Tools
- Practice Quiz 1: ◇[QZ] CSOPESY Practice Quiz 1 - OS Foundations
- Practice Quiz 2: ◇[QZ] CSOPESY Practice Quiz 2 - CPU Scheduling
- Finals Reviewer: ◇[REV] CSOPESY Comprehensive Finals Reviewer
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
An operating system is best described as which of the following from the System View perspective?
Hardware provides a mechanism to prevent user programs from executing instructions like halting the CPU or directly accessing another process's memory. What hardware feature enables this protection?
A system checks its L1 cache first. On a miss, it then accesses main memory. Given , ns, and ns, compute the Effective Access Time (EAT) using the sequential access model.
A Zombie process differs from an Orphan process in that:
A device controller for a high-speed NVMe SSD transfers 1 MB of data to RAM. The OS uses DMA. How many CPU interrupts does this transfer generate?
A read() call on a socket returns immediately with EAGAIN. The calling thread continues executing other code and re-checks the socket after completing its UI update. Which I/O model does this exemplify?
Which of the following is a User Service provided by the OS, as opposed to a System Efficiency Service?
In the program build pipeline — Source → Compiler → Assembler → [X] → Loader — what does component [X] do?
A Monolithic Kernel has a buggy device driver for a new graphics card. What is the most likely system-level consequence?
According to Amdahl's Law, an application has 20% sequential code () and 80% parallelizable code. With processors, what is the maximum achievable speedup?
Thread A and Thread B both share a global integer total. Both threads read total = 100, increment it, and write back. After both complete, total = 101 instead of 102. This is caused by:
A thread calls wait(S) on a semaphore initialized to 0. What happens to the calling thread?
Process P1 holds Lock A and requests Lock B. Process P2 holds Lock B and requests Lock A. Both are suspended, waiting indefinitely. Which necessary condition for deadlock does this most directly demonstrate?
A Round Robin scheduler uses a very small time quantum (e.g., 1ms). What is the primary performance concern?
Which CPU scheduling criterion measures the total elapsed time from when a process is submitted to when it completes — including all waiting and execution time?
Under SRTF (Shortest Remaining Time First), which process will be selected next from the ready queue at the given snapshot?
| Process | Remaining Burst |
|---|---|
| P1 | 6 ms |
| P2 | 2 ms |
| P3 | 4 ms |
| P4 | 9 ms |
A POSIX thread is created with pthread_create(). The main thread then calls pthread_join(). What does pthread_join() do?
Memory-Mapped I/O means that:
A web browser uses one thread for the UI, one for network requests, and one for JavaScript execution — all within the same browser process. If the network thread blocks waiting for a server response, what happens in a One-to-One threading model?
A spooler daemon intercepts print jobs from multiple applications, queues them to disk, and sends them to the printer one at a time. Which kernel I/O service is this?
The process of saving a currently running process's register state and program counter into its PCB, then loading the next process's PCB to resume it, is called:
In Peterson's Solution for the Critical Section Problem, two shared variables are used: flag[2] and turn. What does setting flag[i] = true signify?
Which of the following best describes Thread-Local Storage (TLS)?
The fork() system call returns a different value to the parent and child process. What does fork() return to the parent process?
Non-preemptive Priority Scheduling without aging can result in which of the following problems?